<!-- This HTML file has been created by texi2html 1.29
     from ext2fs.texi on 3 August 1994 -->

<TITLE>Analysis of the Ext2fs structure - Superblock</TITLE>
<P>Go to the <A HREF="ext2fs_3.html">previous</A>, <A HREF="ext2fs_5.html">next</A> section.<P>
<H1><A NAME="SEC4" HREF="ext2fs_toc.html#SEC4">Superblock</A></H1>
<P>
In this section, the layout of a superblock is described. Here is the
official structure of an ext2fs superblock [include/linux/ext2_fs.h]:
<P>
<PRE>
struct ext2_super_block {
  unsigned long  s_inodes_count;
  unsigned long  s_blocks_count;
  unsigned long  s_r_blocks_count;
  unsigned long  s_free_blocks_count;
  unsigned long  s_free_inodes_count;
  unsigned long  s_first_data_block;
  unsigned long  s_log_block_size;
  long           s_log_frag_size;
  unsigned long  s_blocks_per_group;
  unsigned long  s_frags_per_group;
  unsigned long  s_inodes_per_group;
  unsigned long  s_mtime;
  unsigned long  s_wtime;
  unsigned short s_mnt_count;
  short          s_max_mnt_count;
  unsigned short s_magic;
  unsigned short s_state;
  unsigned short s_errors;
  unsigned short s_pad;
  unsigned long  s_lastcheck;
  unsigned long  s_checkinterval;
  unsigned long  s_reserved[238];
};
</PRE>
<P>
<DL COMPACT>
<DT><CODE>s_inodes_count</CODE>
<DD>the total number of inodes on the fs.
<P>
<DT><CODE>s_blocks_count</CODE>
<DD>the total number of blocks on the fs.
<P>
<DT><CODE>s_r_blocks_count</CODE>
<DD>the total number of blocks reserved for the exclusive use of the
superuser.
<P>
<DT><CODE>s_free_blocks_count</CODE>
<DD>the total number of free blocks on the fs.
<P>
<DT><CODE>s_free_inodes_count</CODE>
<DD>the total number of free inodes on the fs.
<P>
<DT><CODE>s_first_data_block</CODE>
<DD>the position on the fs of the first data block. Usually, this is block
number 1 for fs containing 1024 bytes blocks and is number 0 for other
fs.
<P>
<DT><CODE>s_log_block_size</CODE>
<DD>used to compute the logical block size in bytes. The logical block size
is in fact <CODE>1024 &#60;&#60; s_log_block_size</CODE>.
<P>
<DT><CODE>s_log_frag_size</CODE>
<DD>used to compute the logical fragment size. The logical fragment size is
in fact <CODE>1024 &#60;&#60; s_log_frag_size</CODE> if <CODE>s_log_frag_size</CODE> is positive
and <CODE>1024 &#62;&#62; -s_log_frag_size</CODE> if <CODE>s_log_frag_size</CODE> is negative.
<P>
<DT><CODE>s_blocks_per_group</CODE>
<DD>the total number of blocks contained in a group.
<P>
<DT><CODE>s_frags_per_group</CODE>
<DD>the total number of fragments contained in a group.
<P>
<DT><CODE>s_inodes_per_group</CODE>
<DD>the total number of inodes contained in a group.
<P>
<DT><CODE>s_mtime</CODE>
<DD>the time at which the last mount of the fs was performed.
<P>
<DT><CODE>s_wtime</CODE>
<DD>the time at which the last write of the superblock on the fs was performed.
<P>
<DT><CODE>s_mnt_count</CODE>
<DD>the number of time the fs has been mounted in read-write mode without having
been checked.
<P>
<DT><CODE>s_max_mnt_count</CODE>
<DD>the maximum number of time the fs may be mounted in read-write mode before a
check must be done.
<P>
<DT><CODE>s_magic</CODE>
<DD>a magic number that permits the identification of the file system. It is
<CODE>0xEF53</CODE> for a normal ext2fs and <CODE>0xEF51</CODE> for versions of
ext2fs prior to 0.2b.
<P>
<DT><CODE>s_state</CODE>
<DD>the state of the file system. It contains an or'ed value of EXT2_VALID_FS
(0x0001) which means: unmounted cleanly; and EXT2_ERROR_FS (0x0002) which
means: errors detected by the kernel code.
<P>
<DT><CODE>s_errors</CODE>
<DD>indicates what operation to perform when an error occurs. See section <A HREF="ext2fs_10.html#SEC10">Error Handling</A>
<P>
<DT><CODE>s_pad</CODE>
<DD>unused.
<P>
<DT><CODE>s_lastcheck</CODE>
<DD>the time of the last check performed on the fs.
<P>
<DT><CODE>s_checkinterval</CODE>
<DD>the maximum possible time between checks on the fs.
<P>
<DT><CODE>s_reserved</CODE>
<DD>unused.
</DL>
<A NAME="IDX19"></A>
<P>
Times are measured in seconds since  00:00:00 GMT, January 1, 1970.
<P>
Once the superblock is read in memory, the ext2fs kernel code calculates
some other information and keeps them in another structure. This structure
has the following layout:
<P>
<PRE>
struct ext2_sb_info {
	unsigned long s_frag_size;
	unsigned long s_frags_per_block;
	unsigned long s_inodes_per_block;
	unsigned long s_frags_per_group;
	unsigned long s_blocks_per_group;
	unsigned long s_inodes_per_group;
	unsigned long s_itb_per_group;
	unsigned long s_desc_per_block;
	unsigned long s_groups_count;
	struct buffer_head * s_sbh;
	struct ext2_super_block * s_es;
	struct buffer_head * s_group_desc[EXT2_MAX_GROUP_DESC];
	unsigned short s_loaded_inode_bitmaps;
	unsigned short s_loaded_block_bitmaps;
	unsigned long s_inode_bitmap_number[EXT2_MAX_GROUP_LOADED];
	struct buffer_head * s_inode_bitmap[EXT2_MAX_GROUP_LOADED];
	unsigned long s_block_bitmap_number[EXT2_MAX_GROUP_LOADED];
	struct buffer_head * s_block_bitmap[EXT2_MAX_GROUP_LOADED];
	int s_rename_lock;
	struct wait_queue * s_rename_wait;
	unsigned long  s_mount_opt;
	unsigned short s_mount_state;
};
</PRE>
<P>
<DL COMPACT>
<DT><CODE>s_frag_size</CODE>
<DD>fragment size in bytes.
<P>
<DT><CODE>s_frags_per_block</CODE>
<DD>number of fragments in a block.
<P>
<DT><CODE>s_inodes_per_block</CODE>
<DD>number of inodes in a block of the inode table.
<P>
<DT><CODE>s_frags_per_group</CODE>
<DD>number of fragments in a group.
<P>
<DT><CODE>s_blocks_per_group</CODE>
<DD>number of blocks in a group.
<P>
<DT><CODE>s_inodes_per_group</CODE>
<DD>number of inodes in a group.
<P>
<DT><CODE>s_itb_per_group</CODE>
<DD>number of inode table blocks per group.
<P>
<DT><CODE>s_desc_per_block</CODE>
<DD>number of group descriptors per block.
<P>
<DT><CODE>s_groups_count</CODE>
<DD>number of groups.
<P>
<DT><CODE>s_sbh</CODE>
<DD>the buffer containing the disk superblock in memory.
<P>
<DT><CODE>s_es</CODE>
<DD>pointer to the superblock in the buffer.
<P>
<DT><CODE>s_group_desc</CODE>
<DD>pointers to the buffers containing the group descriptors.
<P>
<DT><CODE>s_loaded_inode_bitmaps</CODE>
<DD>number of inodes bitmap cache entries used.
<P>
<DT><CODE>s_loaded_block_bitmaps</CODE>
<DD>number of blocks bitmap cache entries used.
<P>
<DT><CODE>s_inode_bitmap_number</CODE>
<DD>indicates to which group the inodes bitmap in the buffers belong.
<P>
<DT><CODE>s_inode_bitmap</CODE>
<DD>inode bitmap cache.
<P>
<DT><CODE>s_block_bitmap_number</CODE>
<DD>indicates to which group the blocks bitmap in the buffers belong.
<P>
<DT><CODE>s_block_bitmap</CODE>
<DD>block bitmap cache.
<P>
<DT><CODE>s_rename_lock</CODE>
<DD>lock used to avoid two simultaneous rename operations on a fs.
<P>
<DT><CODE>s_rename_wait</CODE>
<DD>wait queue used to wait for the completion of a rename operation in progress.
<P>
<DT><CODE>s_mount_opt</CODE>
<DD>the mounting options specified by the administrator.
<P>
<DT><CODE>s_mount_state</CODE>
<DD></DL>
<P>
Most of those values are computed from the superblock on disk.
<A NAME="IDX20"></A>
<A NAME="IDX21"></A>
<P>
Linux ext2fs manager caches access to the inodes and blocks
bitmaps. This cache is a list of buffers ordered from the most recently
used to the last recently used buffer. Managers should use the same kind
of bitmap caching or other similar method of improving access time to
disk.
<P>
<P>Go to the <A HREF="ext2fs_3.html">previous</A>, <A HREF="ext2fs_5.html">next</A> section.<P>
